home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / docs / ippon / ver / 005 / player.c < prev   
C/C++ Source or Header  |  2000-07-07  |  3KB  |  127 lines

  1. /* player.c */
  2.  
  3. #include <sys/iocs.h>
  4. #include <xsp2lib.h>
  5.  
  6. #include "main.h"
  7. #include "player.h"
  8.  
  9. #define PLAYER_BANK1    8    /* 少し傾きパターンへ移行するまでの値 */
  10. #define PLAYER_BANK2    12    /* 一番傾きパターンへ以下同文 */
  11.  
  12. #define PLAYER_SPEED    15    /* 自機の速度 */
  13.  
  14.  
  15. enum {
  16.     PLAYER_PT_RIGHT2 = 0,    /* 自機が一番右に傾いている時のパターン */
  17.     PLAYER_PT_RIGHT1,    /*  〃 少し右に     〃      */
  18.     PLAYER_PT_CENTER,    /*  〃 正面を向いている時のパターン */
  19.     PLAYER_PT_LEFT1,    /* 自機が少し右に傾いている時のパターン */
  20.     PLAYER_PT_LEFT2        /*  〃 一番右に     〃      */
  21. };
  22.  
  23.  
  24.  
  25. /* ゲーム開始時に呼ばれる */
  26. void PlayerInit (void)
  27. {
  28. }
  29.  
  30.  
  31.  
  32. /* プレイヤー出現時に呼ばれる */
  33. void PlayerAlloc (void)
  34. {
  35.     player->lx = 144 * 65536;
  36.     player->ly = 144 * 65536;
  37.     player->bank = 0;
  38. }
  39.  
  40.  
  41.  
  42. /* 垂直同期ごとに呼ばれる */
  43. void PlayerMove (void)
  44. {
  45.     int j;            /* ジョイスティックの入力 */
  46.  
  47.     j = _iocs_joyget (0);    /* ジョイスティック0番 */
  48.  
  49.     /* [A] ボタンが押されたか? */
  50.     if ((j & 0b00100000) == 0)
  51.         game_over = !0;    /* ゲームオーバーに */
  52.  
  53.     /* 自機の上下移動処理 */
  54.     switch (j & 0b0011) {
  55.     case 0b0010:        /* 上 */
  56.         player->ly += xytable[PLAYER_SPEED][192].y;
  57.         break;
  58.     case 0b0001:        /* 下 */
  59.         player->ly += xytable[PLAYER_SPEED][64].y;
  60.         break;
  61.     default:        /* それ以外 */
  62.         break;
  63.     }
  64.  
  65.     /* 自機の左右移動処理+左右傾き処理 */
  66.     switch (j & 0b1100) {
  67.     case 0b1000:        /* 左 */
  68.         player->lx += xytable[PLAYER_SPEED][128].x;
  69.         if (player->bank > 0) {
  70.             player->bank = 0;
  71.         } else {
  72.             if (player->bank > -PLAYER_BANK2)
  73.                 player->bank--;
  74.         }
  75.         break;
  76.  
  77.     case 0b0100:        /* 右 */
  78.         player->lx += xytable[PLAYER_SPEED][0].x;
  79.         if (player->bank < 0) {
  80.             player->bank = 0;
  81.         } else {
  82.             if (player->bank < PLAYER_BANK2)
  83.                 player->bank++;
  84.         }
  85.         break;
  86.  
  87.     default:        /* それ以外 */
  88.         /* 自機の傾きを元に戻す処理 */
  89.         if (player->bank != 0) {
  90.             if (player->bank > 0)
  91.                 player->bank--;
  92.             else
  93.                 player->bank++;
  94.         }
  95.         break;
  96.     }
  97.  
  98.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  99.     if (player->bank == 0) {
  100.         player->pt = obj_player + PLAYER_PT_CENTER;
  101.     } else {
  102.         if (player->bank > 0) {
  103.             if (player->bank < PLAYER_BANK1)
  104.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  105.             else
  106.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  107.         } else {
  108.             if (player->bank > -PLAYER_BANK1)
  109.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  110.             else
  111.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  112.         }
  113.     }
  114.  
  115.     player->x = player->lx / 65536;
  116.     player->y = player->ly / 65536;
  117.  
  118.     xobj_set (player->x, player->y, player->pt, 0x073f);    /* 自機を表示 */
  119. }
  120.  
  121.  
  122.  
  123. /* プレイヤー消去時に呼ばれる */
  124. void PlayerFree (void)
  125. {
  126. }
  127.